package com.jsd2412.backend.employee.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.jsd2412.backend.base.response.JsonResult;
import com.jsd2412.backend.employee.pojo.dto.EmployeeLoginParam;
import com.jsd2412.backend.employee.pojo.vo.EmployeeVO;
import com.jsd2412.backend.employee.service.EmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;

@Slf4j
@RestController
@Api(tags = "员工管理模块")
@RequestMapping("/v1/employee/")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    @PostMapping("login")
    @ApiOperation("员工登录")
    @ApiOperationSupport(order = 10)
    public JsonResult login(EmployeeLoginParam employeeLoginParam,
                            @ApiIgnore HttpSession session) {
        log.debug("员工登录:参数={}", employeeLoginParam);
        EmployeeVO employeeVO = employeeService.login(employeeLoginParam, session);
        return JsonResult.ok(employeeVO);
    }

    @GetMapping("currentemployee")
    @ApiOperation("获取当前员工")
    @ApiOperationSupport(order = 20)
    public JsonResult currentEmployee(@ApiIgnore HttpSession session) {
        log.debug("获取当前员工");
        EmployeeVO employeeVO = employeeService.currentEmployee(session);
        return JsonResult.ok(employeeVO);
    }

    @GetMapping("logout")
    @ApiOperation("退出登录")
    @ApiOperationSupport(order = 30)
    public JsonResult logout(@ApiIgnore HttpSession session) {
        log.debug("退出登录");
        employeeService.logout(session);
        return JsonResult.ok();
    }
}
